import axios from "axios";

//封装get本质就是由装饰器代替调用getList方法

const doc = (url: string): MethodDecorator => {
  return function (target: any, key: any, descriptor: any) {
    const fnc = descriptor.value;

    axios
      .get(url)
      .then((res) => {
        fnc(res, {
          code: 200,
          success: true,
        });
      })
      .catch((err) => {
        fnc(err, {
          code: 501,
          success: false,
        });
      });
  };
};

class Control {
  constructor() {}

  @doc("https://api.apiopen.top/api/getHaoKanVideo?page=0&size=10")
  getList(res: any, status: any) {
    console.log(res.data.result, status);
  }
}

const dzx = new Control();
